import BASE_URLS from "@/api/config.js"
import http from "@/utils/http.js"
const userService = {
	getSmsCode: function(phone) {
		return http.request({
			url: BASE_URLS.DEFAULT_BASE_URL + "/phone/code",
			data: {
				phone: phone,
				code: "",
				isNeedValidate: false
			},
			method: "GET",
			header: {
				"content-type": "application/json"
			}
		});
	},
	// 注册
	register: function(params) {
		return http.request({
			url: BASE_URLS.DEFAULT_BASE_URL + "/sysUser/register",
			data: params,
			method: "POST",
			header: {
				"content-type": "application/json"
			}
		});
	},
	// 找回密码
	findBackPwd: function(params) {
		return http.request({
			url: BASE_URLS.DEFAULT_BASE_URL + "/reset/password",
			data:params,
			method: "POST",
			header: {
				"content-type": "application/json"
			}
		});
	},
	// 登录
	login: function(params) {
		return http.request({
			url: BASE_URLS.DEFAULT_BASE_URL + "/login",
			data: params,
			method: "POST",
			header: {
				"content-type": "application/x-www-form-urlencoded"
			}
		});
	},
	// 退出
	logout: function() {
		return http.request({
			url: BASE_URLS.DEFAULT_BASE_URL + "/logout",
			method: "GET"
		});
	},
	// 获取用户信息
	getUserInfo: function() {
		return http.request({
			url: BASE_URLS.DEFAULT_BASE_URL + "/myinfo",
			method: "GET",
			header: {
				"token": uni.getStorageSync("token")
			}
		}).then((res) => {
			console.log(JSON.stringify(res.data));
			uni.showToast({
				icon: "none",
				title: res.data.msg,
				duration: 2000
			});
			if (res.data.success) {

				uni.setStorage({
					key: "userinfo",
					data: res.data.data,
					success: function(res) {
						console.log('个人信息缓存成功');
					}
				})
			}
		});
	},
	//修改密码
	changePwd: function(params) {
		return http.request({
			url: BASE_URLS.DEFAULT_BASE_URL + "/change/mypwd",
			data: params,
			method: "POST",
			header: {
				"content-type": "application/x-www-form-urlencoded",
				"token": uni.getStorageSync("token")
			}
		});
	},
	//提交实名认证信息（司机）
	submitIdentity: function(params) {
		return http.request({
			url: BASE_URLS.DEFAULT_BASE_URL + "/baseinfo/auth/driver/save",
			data: params,
			method: "POST",
			header: {
				"content-type": "application/x-www-form-urlencoded",
				"token": uni.getStorageSync("token")
			}
		});
	},
	//获取实名认证结果（司机）
	getIdentity: function() {

		return http.request({
			url: BASE_URLS.DEFAULT_BASE_URL + "/baseinfo/driver/get/auth",
			method: "GET",
			header: {
				"token": uni.getStorageSync("token")
			}
		});
	},
}
export default userService
